package org.hades.corelib.utils.device

import android.os.Build
import android.view.View
import android.view.Window
import android.view.WindowManager
import androidx.annotation.ColorInt
import androidx.core.graphics.ColorUtils


fun Window.barColor(@ColorInt color: Int){
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        // 设置状态栏底色颜色
        this.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        this.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        this.statusBarColor = color;

        // 如果亮色，设置状态栏文字为黑色
        if (ColorUtils.calculateLuminance(color) >= 0.5){
            this.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
        }else{
            this.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE;
        }
    }
}
class StatusBar {
}